﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CarHelpDesk.Web.Models;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using System.Data.SqlClient;
using System.IO;

namespace CarHelpDesk.Web.Tests.TestHelpers
{
    static class CInitializeTestData
    {

        public static void InitializeDatabase()
        {
            InitializeDatabaseFromFile("../../../db/FillTestdata.sql");
        }


        public static void InitializeSimpleDatabase()
        {
            InitializeDatabaseFromFile("../../../db/FillSimpleTestData.sql");
        }

        private static void InitializeDatabaseFromFile(string filename)
        {
            string sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; ;// @"Data Source=95.111.33.9\SQLEXPRESS;Initial Catalog=db_helpdesk_test;User ID=WebUser;Password=fmigroup";
            FileInfo file = new FileInfo(filename);
            string script = file.OpenText().ReadToEnd();
            SqlConnection conn = new SqlConnection(sqlConnectionString);
            Server server = new Server(new ServerConnection(conn));
            server.ConnectionContext.ExecuteNonQuery(script);
        }

    }
}
